package cn.wolfcode.web.controller;

import cn.wolfcode.domain.Permission;
import cn.wolfcode.quest.JsonResult;
import cn.wolfcode.quest.QueryObject;
import cn.wolfcode.result.PageResult;
import cn.wolfcode.service.IPermissionService;
import cn.wolfcode.util.RequiredPermission;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@RequestMapping("/permission")
@Controller
public class PermissionController {
    @Autowired
    private IPermissionService permissionService;
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") QueryObject qo){
        //点击重新加载,调用业务层方法,保存权限对象集合,并返回
        PageInfo result = permissionService.query(qo);

        //放到作用域中
        model.addAttribute("pageResult", result);
        System.out.println(result);
        return "permission/list";
    }
    @RequestMapping("/reload")
    @ResponseBody
    public JsonResult reload(){
        JsonResult jsonResult = new JsonResult();
        permissionService.reload();
        return jsonResult;
    }

    @RequestMapping("/delete")
    @ResponseBody
    public JsonResult delete(Long id){
        JsonResult jsonResult = new JsonResult();
        permissionService.deleteByPrimaryKey(id);
        return jsonResult;
    }
}
